
#ifndef __MAIN_H
#define __MAIN_H


#include "gd32f30x.h"





enum AdminAuthority
{
		
    AuthorityAddTask = 0x0001,	   AuthorityDelTask = 0x0002,		 AuthorityAddDev = 0x0004,       AuthorityDelDev = 0x0008,
    AuthorityConfigID = 0x0010,	   AuthorityConfigFun = 0x0020,  AuthorityConfigRemote = 0x0040, AuthorityConfigLora = 0x0080,
    AuthorityConfigBuzzer = 0x0100,AuthorityConfigLed = 0x0200,  AuthorityInquire = 0x0400,		   AuthorityControlTask=0x0800,
		AuthorityBootloader = 0x1000,  AuthorityCheckTime = 0x2000,  AuthorityRestart = 0x4000,      AuthorityRefactory = 0x8000,
		AuthorityAddRoom = 0x10000,    AuthorityDelRoom = 0x20000,
	
		AuthorityUserNORMAL = AuthorityInquire | AuthorityControlTask | AuthorityCheckTime,
		
		AuthorityUserFLECHAZO = 0xFFFF,
};

typedef union
{
    struct
    {
        uint32_t  	AddTask: 1;
        uint32_t   	DelTask : 1;
        uint32_t   	AddDev : 1;
        uint32_t   	DelDev : 1;

        uint32_t   	ConfigID : 1;
        uint32_t   	ConfigFun : 1;
        uint32_t   	ConfigRemote : 1;
        uint32_t   	ConfigLora : 1;

        uint32_t   	ConfigBuzzer : 1;
        uint32_t   	ConfigLed : 1;
        uint32_t    Inquire: 1;
				uint32_t    ControlTask:1;
			
        uint32_t   	Bootloader : 1;
        uint32_t   	CheckTime : 1;
        uint32_t    Restart: 1;
				uint32_t    Refactory:1;		
				
				uint32_t    AddRoom:1;
				uint32_t    DelRoom:1;
				
    } Info;
    uint32_t Byte;
} Authority_union;


#define GotoAppGuide 0x08004FF0
#define DefaultAppBurnPos 1   //1->APP1 | others->APP2

//Enumeration of received task instructions
enum CommandEnum
{
		CMDIntoBootloaderMode = 0x1F,
    CMDIntoDebugMode = 0x77,
	
		CMDGotoApp1 = 0xA1,CMDGotoApp2 = 0xA2,
		CMDDelApp1 = 0x41,CMDDelApp2 = 0x42,
		
		CMDRestart = 0x1E,
	
};


typedef struct
{
	bool status;
	bool loaderEnd;
	
	uint8_t bootloaderpackage;
	uint8_t bootloaderpackagecount;
	
	uint32_t bootloaderWaitTime;
	uint32_t bootloaderTime;
	
	uint32_t bootloaderbytecount;
	uint32_t bootloaderbitcount;
	
	uint32_t timeout;
	uint32_t erasePage;
	unsigned int crccompare;
	uint8_t Info[64];
	uint8_t AppData[4096];
	bool updataflag;
	
	
}Bootloader_struct;



#endif
